clear all;
clf;
%create a weighted undirected graph
n=2; % number of nodes
%graph=rand(n,n);

a = 0;
b = 1;

x = a + (b-a).*rand(n,1);
y = a + (b-a).*rand(n,1);

xx(1:n) = x;
yy(1:n) = y;

plot(x,y,'+');

hold on;

a = 2.5;
b = 3;

x = a + (b-a).*rand(n,1);
y = a + (b-a).*rand(n,1);

xx(1+n:n+n) = x(1:end);
yy(1+n:n+n) = y;

plot(xx,yy,'^');

hold off;


for i=1:n+n
    for j=1:n+n
        graph(i,j) = sqrt((xx(i)-xx(j))^2+(yy(i)-yy(j))^2);        
    end
end
% % 
% % for i=1:n
% %     for j=(i+1):n
% %         graph(j,i)=graph(i,j);
% %     end
% % end
% 

sigma2 = median(graph(:));
graph = exp(-graph);

grapha = pdist2([xx' yy'],[xx' yy'],'seuclidean');
sigma2 = median(grapha(:));
grapha = exp(-grapha/sigma2);

[groups,no_groups,cost_function,f_ini]=iterative_dominant_set_extraction(grapha);
% 
gscatter(xx,yy,groups,[],'ox+*sdv^<>ph.')
% % plot(x,y,groups,'o+');